package com.hsq.spzx.manager.task;

import cn.hutool.core.date.DateUtil;
import com.hsq.spzx.manager.interceptor.LoginAuthInterceptor;
import com.hsq.spzx.manager.mapper.order.OrderInfoMapper;
import com.hsq.spzx.manager.mapper.order.OrderStatisticsMapper;
import com.hsq.spzx.model.entity.order.OrderStatistics;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.Date;

/**
 * @author hsq
 * @date 2025-06-12 下午3:42
 */
@Component
@Slf4j
public class OrderStatisticsTask {
    @Autowired
    private OrderInfoMapper orderInfoMapper;
    @Autowired
    private OrderStatisticsMapper orderStatisticsMapper;

//    @Scheduled(cron = "0/10 * * * * ?")  // 定义定时任务，使用@Scheduled注解指定调度时间表达式
    @Scheduled(cron = "0 0 2 * * ?")
    public void orderTotalAmountStatistics() {
//        log.error("定时成功: {}", new Date());
        String createTime = DateUtil.offsetDay(new Date(), -1).toString("yyyy-MM-dd");
        OrderStatistics orderStatistics = orderInfoMapper.selectOrderStatistics(createTime);
        if(orderStatistics != null) {
            orderStatisticsMapper.insert(orderStatistics) ;
        }
    }
}
